package kislo.dima.task1;

import java.util.ArrayList;
import java.util.List;

public class Matrix {

	private int[][] array;

	public Matrix(int m, int n) {
		array = new int[m][n];
	}

	public int getRowCount() {
		return array.length;
	}

	public int getColumnCount() {
		return array[0].length;
	}

	public int getElement(int i, int j) {
		return array[i][j];
	}

	public void setElement(int i, int j, int value) {
		array[i][j] = value;
	}

	public String toString() {
		String s = "Matrix [" + array.length + ", " + array[0].length + "]\n";
		for (int[] row : array) {
			for (int value : row)
				s += value + " ";
			s += "\n";
		}
		return s;
	}

	public int findMin() {
		int min = array[0][0];
		for (int[] row : array)
			for (int value : row)
				if (value < min)
					min = value;
		return min;
	}

	public int findMax() {
		int max = array[0][0];
		for (int[] row : array)
			for (int value : row)
				if (value > max)
					max = value;
		return max;
	}

	public List<Coordinate> coordinateMin() {
		List<Coordinate> list = new ArrayList<Coordinate>();
		int value = findMin();
		for (int i = 0; i < array.length; i++)
			for (int j = 0; j < array[i].length; j++)
				if (array[i][j] == value)
					list.add(new Coordinate(i, j));
		return list;
	}

	public List<Coordinate> coordinateMax() {
		List<Coordinate> list = new ArrayList<Coordinate>();
		int value = findMax();
		for (int i = 0; i < array.length; i++)
			for (int j = 0; j < array[i].length; j++)
				if (array[i][j] == value)
					list.add(new Coordinate(i, j));
		return list;
	}
}
